#!/usr/bin/python
import sys, os #--
import pygst #--
pygst.require("0.10") #--
import gst #--
import pygtk #--
pygtk.require('2.0') #--
import gtk, gtk.glade #--
#--
#=010 name the 'tee'
#=020 connect the left pipeline
#=030 to the mixer
#=040 and out to the audio device
#=050 connect the right pipeline
PIPELINE = """filesrc location=%s ! mad 
! tee name=t  #010
t.src0 ! queue ! audioconvert ! ladspa-lpf 
       ! volume name=bass ! audioconvert #020
       ! adder name=mix #030
       ! volume name=master ! alsasink device=plughw:2  #040
t.src1 ! queue ! audioconvert ! mix.  #050
"""

class Bass:
    def __init__(self):
        # Setup the GUI from the Glade file #--
        gladeFile = os.path.join(os.path.dirname(__file__,), 'bass.glade') #--
        self.xml = gtk.glade.XML(gladeFile, None) #--
        self.xml.signal_autoconnect(self) #--
        window = self.xml.get_widget("main") #--
        window.connect('delete-event', gtk.main_quit) #--
        window.show_all() #--
 #--
        # Create the pipeline #--
        self.pipeline = gst.parse_launch(PIPELINE % (sys.argv[1]))

        self.master = self.pipeline.get_by_name('master')
        self.bass = self.pipeline.get_by_name('bass')

    def on_playButton_clicked(self, widget):
        # Start the pipeline
        self.pipeline.set_state(gst.STATE_PLAYING)

    def on_pauseButton_clicked(self, widget):
        # Pause the pipeline
        self.pipeline.set_state(gst.STATE_PAUSED)
            
    def on_masterScale_value_changed(self, w):
        scale = w.get_value() 
        self.master.set_property('volume', scale/100)
        
    def on_bassScale_value_changed(self, w):
        scale = w.get_value() 
        self.bass.set_property('volume', scale/100)

    def on_quit_activate(self, widget):
        gtk.main_quit()

if __name__ == "__main__":
    bass=Bass()
    gtk.main()
